package com.xinruke.hostels.dailymanage.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.EConditionOperator;
import com.xinruke.hostels.common.vo.query.QueryConditions;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.dailymanage.interfaces.dto.inhotel.*;
import com.xinruke.hostels.dailymanage.service.InHotelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author ChenXiangpeng
 * @ClassName InHotelInnerApiController
 * @date：2019/7/31
 * @version: V1.0.0
 * @description：
 */
@RestController
@RequestMapping("/inHotelInnerApi/")
@Api(tags = "入住订单管理")
@Slf4j
public class InHotelInnerApiController extends BaseController {
    @Autowired
    InHotelService inHotelService;

    @PostMapping("/hotel/list")
    @ApiOperation("获取入住集合")
    public ResultVO<RowsDataVO<InHotelQueryResultDTO>> getInHotelList(@RequestBody @Valid InHotelQueryByHotelIdDTO inHotelQueryDTO) {
        ResultVO<RowsDataVO<InHotelQueryResultDTO>> resultVO = ResultVO.fail();

        QueryConditions dingdanQueryConditions = inHotelQueryDTO.getQueryConditions();
        dingdanQueryConditions.addCondition("zhuangtai", EConditionOperator.EQULS, inHotelQueryDTO.getZhuangtai());
        dingdanQueryConditions.addCondition("ruzhuleixing", EConditionOperator.EQULS, inHotelQueryDTO.getRuzhuleixing());
        dingdanQueryConditions.addCondition("ruzhushijian", EConditionOperator.GREATER, inHotelQueryDTO.getRuzhushijianStart());
        dingdanQueryConditions.addCondition("ruzhushijian", EConditionOperator.LESS, inHotelQueryDTO.getRuzhushijianEnd());
        dingdanQueryConditions.addCondition("likaishijian", EConditionOperator.GREATER, inHotelQueryDTO.getLikaishijianStart());
        dingdanQueryConditions.addCondition("likaishijian", EConditionOperator.LESS, inHotelQueryDTO.getLikaishijianEnd());
        dingdanQueryConditions.addCondition("yudingriqi", EConditionOperator.GREATER, inHotelQueryDTO.getYudingriqiStart());
        dingdanQueryConditions.addCondition("yudingriqi", EConditionOperator.LESS, inHotelQueryDTO.getYudingriqiEnd());
        dingdanQueryConditions.addCondition("yudingrenxingming", EConditionOperator.EQULS, inHotelQueryDTO.getYudingrenxingming());
        dingdanQueryConditions.addCondition("yudingrendianhua", EConditionOperator.EQULS, inHotelQueryDTO.getYudingrendianhua());
        dingdanQueryConditions.addCondition("dingdanhao", EConditionOperator.EQULS, inHotelQueryDTO.getDingdanhao());
        dingdanQueryConditions.addCondition("yudingdingdanhao", EConditionOperator.EQULS, inHotelQueryDTO.getYudingdingdanhao());
        dingdanQueryConditions.addCondition("laiyuan", EConditionOperator.EQULS, inHotelQueryDTO.getLaiyuan());

        RowsDataVO rowsDataVO = inHotelService.getInHotelListByHotelId(inHotelQueryDTO);

        resultVO = ResultVO.success();
        resultVO.setData(rowsDataVO);

        return resultVO;
    }

    @PostMapping("/hotel/detail")
    @ApiOperation("获取入住详情")
    public ResultVO<InHotelDetailQueryResultDTO> getInHotelDetail(@RequestBody @Valid InHotelDetailQueryDTO inHotelDetailQueryDTO) {
        ResultVO<InHotelDetailQueryResultDTO> resultVO = ResultVO.success();
        InHotelDetailQueryResultDTO inHotelDetailQueryResultDTO = inHotelService.getInHotelDetail(inHotelDetailQueryDTO);
        resultVO.setData(inHotelDetailQueryResultDTO);

        return resultVO;
    }
}
